package br.com.maps.contacts.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Creates the database if needed
 * 
 * @author Bruno Ortiz
 * 
 */
public class SQLiteHelper extends SQLiteOpenHelper {

	private static final String CATEGORIA = "contatos";
	private String[] sqlCreate;
	private String[] sqlDelete;

	public SQLiteHelper(Context context, String dbName, int dbVersion, String[] sqlCreate, String[] sqlDelete) {
		super(context, dbName, null, dbVersion);
		this.sqlCreate = sqlCreate;
		this.sqlDelete = sqlDelete;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		Log.i(CATEGORIA, "Creating database");
		for (String sql : this.sqlCreate) {
			Log.i(CATEGORIA, sql);
			db.execSQL(sql);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		for (String sql : this.sqlDelete) {
			Log.i(CATEGORIA, sql);
			db.execSQL(sql);
		}
		this.onCreate(db);
	}

}
